package com.csw.clazzTeacher.controller;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.csw.clazzTeacher.entity.Clazz;
import com.csw.clazzTeacher.service.ClazzService;

@Controller
@RequestMapping("clazz")
public class ClazzController {

	// 注入clazzService
	@Autowired
	private ClazzService clazzService;

	// 查询所有班级json
	@RequestMapping("findAllClazzsJson")
	@ResponseBody
	public List<Clazz> findAllClazzsJson() {
		return clazzService.findAll();
	}

	// 保存班级
	@RequestMapping("saveClazz")
	public String save(Clazz clazz) {
		clazzService.save(clazz);
		return "redirect:/clazz/findAllClazzs";
	}

	// 查询所有
	@RequestMapping("findAllClazzs")
	public String findAll(Model model) {
		List<Clazz> clazzes = clazzService.findAll();
		model.addAttribute("clazzes", clazzes);
		return "clazz/index";
	}
}
